﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class hoadonDAL:VO.ketnoi
    {
        public List<VO.hoadonVO> hoadon_xem()
        {
            List<VO.hoadonVO> list = new List<VO.hoadonVO>();
            using (SqlCommand dbCmd = new SqlCommand("hoadon_xem", GetConnection()))
            {
                VO.hoadonVO obj = new VO.hoadonVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.hoadonIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool hoadon_them(VO.hoadonVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("hoadon_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@giahh", data.GiaHh));
                    dbCmd.Parameters.Add(new SqlParameter("@kh", data.Kh));
                    dbCmd.Parameters.Add(new SqlParameter("@mahd", data.MaHd));
                    dbCmd.Parameters.Add(new SqlParameter("@ngay", data.Ngay));
                    dbCmd.Parameters.Add(new SqlParameter("@nv", data.Nv));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool hoadon_sua(VO.hoadonVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("hoadon_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@giahh", data.GiaHh));
                dbCmd.Parameters.Add(new SqlParameter("@kh", data.Kh));
                dbCmd.Parameters.Add(new SqlParameter("@mahd", data.MaHd));
                dbCmd.Parameters.Add(new SqlParameter("@ngay", data.Ngay));
                dbCmd.Parameters.Add(new SqlParameter("@nv", data.Nv));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool hoadon_xoa(string mahd)
        {
            using (SqlCommand dbCmd = new SqlCommand("hoadon_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@mahd", mahd));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
